var xmlHttp;

var local="http://47.104.10.151";

//获取主页的用户
var page=0;
// 订单的id；
var order_id1;
var order_id2;
var order_id3;
var order_id4;
var order_id5;
var order_id6;
//订单编号
var Order_code1;
var Order_code2;
var Order_code3;
var Order_code4;
var Order_code5;
var Order_code6;

var keyId1=getCookie('userId');

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}


function creatxmlHTTP() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlHttp=new XMLHttpRequest();
    }else {
        // IE6, IE5 浏览器执行代码
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
}
function getInvite() {
    var kid=getCookie('userId');
    var url = local+":8080/login/displayCompany_Code";
    var xmlHttp = creatxmlHTTPInvite();
    var txt = "";//用于存储拼接字符串；
    //获取数据
    //拼接字符
    txt = "user_Id=" + kid;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);
    function creatxmlHTTPInvite() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        return xmlHttp;
    }
    xmlHttp.onreadystatechange=function()
    {
        if (xmlHttp.readyState==4 && xmlHttp.status==200)
        {
            var result=xmlHttp.responseText;
            var json=eval("("+result+")");
            document.getElementById("invite_code").value=json.msg;
        }
    }
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}


function onClickAjax_biding_result1() {
    var xmlHttp = creatxmlHTTP();
    var txt = "";//用于存储拼接字符串；
    var url=local+":8080/voteBid/findVoteBidByUserIdAndBid_status";
    //拼接字符
    txt = "user_id=" + keyId1 + "&page=" + page;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(txt);


    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var result = xmlHttp.responseText;
            var json = eval("(" + result + ")");

            totalPages=json.data.totalPages;

            var input1 = document.getElementsByName("bid1");
            if (json.data.content[0].tax_status == 0) {
                input1[11].value = "无税率";
            } else if(json.data.content[0].tax_status == 1){
                input1[11].value = "17%";
            }
            order_id1=json.data.content[0].keyId;
            Order_code1=json.data.content[0].order_code;
            input1[1].value = json.data.content[0].voteBid_code;
            input1[2].value = json.data.content[0].keyId;
            input1[3].value = json.data.content[0].product_name;
            input1[4].value = json.data.content[0].model;
            input1[5].value = json.data.content[0].size;
            input1[6].value = json.data.content[0].brand;
            input1[7].value = json.data.content[0].inventory;
            input1[12].value = json.data.content[0].company_code;
            input1[13].value = json.data.content[0].area;

            input1[14].value = json.data.content[0].deadline;

            input1[15].value = json.data.content[0].bid_status;

            var input2 = document.getElementsByName("bid2");
            if (json.data.content[1].tax_status == 0) {
                input2[11].value = "无税率";
            } else if(json.data.content[1].tax_status == 1){
                input2[11].value = "17%";
            }
            order_id2=json.data.content[1].keyId;
            Order_code2=json.data.content[1].order_code;
            input2[1].value = json.data.content[1].voteBid_code;
            input2[2].value = json.data.content[1].keyId;
            input2[3].value = json.data.content[1].product_name;
            input2[4].value = json.data.content[1].model;
            input2[5].value = json.data.content[1].size;
            input2[6].value = json.data.content[1].brand;
            input2[7].value = json.data.content[1].inventory;
            input2[12].value = json.data.content[1].company_code;
            input2[13].value = json.data.content[1].area;
            input1[14].value = json.data.content[1].deadline;
            input2[15].value = json.data.content[1].bid_status;

            var input3= document.getElementsByName("bid3");
            if (json.data.content[2].tax_status == 0) {
                input3[11].value = "无税率";
            } else if(json.data.content[2].tax_status == 1){
                input3[11].value = "17%";
            }
            order_id3=json.data.content[2].keyId;
            Order_code3=json.data.content[2].order_code;
            input3[1].value = json.data.content[2].voteBid_code;
            input3[2].value = json.data.content[2].keyId;
            input3[3].value = json.data.content[2].product_name;
            input3[4].value = json.data.content[2].model;
            input3[5].value = json.data.content[2].size;
            input3[6].value = json.data.content[2].brand;
            input3[7].value = json.data.content[2].inventory;
            input3[12].value = json.data.content[2].company_code;
            input3[13].value = json.data.content[2].area;
            input1[14].value = json.data.content[2].deadline;
            input3[15].value = json.data.content[2].bid_status;

            var input4 = document.getElementsByName("bid4");
            if (json.data.content[3].tax_status == 0) {
                input4[11].value = "无税率";
            } else if(json.data.content[3].tax_status == 1){
                input4[11].value = "17%";
            }
            order_id4=json.data.content[3].keyId;
            Order_code4=json.data.content[3].order_code;
            input4[1].value = json.data.content[3].voteBid_code;
            input4[2].value = json.data.content[3].keyId;
            input4[3].value = json.data.content[3].product_name;
            input4[4].value = json.data.content[3].model;
            input4[5].value = json.data.content[3].size;
            input4[6].value = json.data.content[3].brand;
            input4[7].value = json.data.content[3].inventory;
            input4[12].value = json.data.content[3].company_code;
            input4[13].value = json.data.content[3].area;
            input1[14].value = json.data.content[3].deadline;
            input4[15].value = json.data.content[3].bid_status;

            var input5 = document.getElementsByName("bid5");
            if (json.data.content[4].tax_status == 0) {
                input5[11].value = "无税率";
            } else if(json.data.content[4].tax_status == 1){
                input5[11].value = "17%";
            }
            order_id5=json.data.content[4].keyId;
            Order_code5=json.data.content[4].order_code;
            input5[1].value = json.data.content[4].voteBid_code;
            input5[2].value = json.data.content[4].keyId;
            input5[3].value = json.data.content[4].product_name;
            input5[4].value = json.data.content[4].model;
            input5[5].value = json.data.content[4].size;
            input5[6].value = json.data.content[4].brand;
            input5[7].value = json.data.content[4].inventory;
            input5[12].value = json.data.content[4].company_code;
            input5[13].value = json.data.content[4].area;
            input1[14].value = json.data.content[4].deadline;
            input5[14].value = json.data.content[4].bid_status;

            var input6= document.getElementsByName("bid6");
            if (json.data.content[5].tax_status == 0) {
                input6[11].value = "无税率";
            } else if(json.data.content[5].tax_status == 1){
                input6[11].value = "17%";
            }
            order_id6=json.data.content[5].keyId;
            Order_code6=json.data.content[5].order_code;
            input6[1].value = json.data.content[5].voteBid_code;
            input6[2].value = json.data.content[5].keyId;
            input6[3].value = json.data.content[5].product_name;
            input6[4].value = json.data.content[5].model;
            input6[5].value = json.data.content[5].size;
            input6[6].value = json.data.content[5].brand;
            input6[7].value = json.data.content[5].inventory;
            input6[12].value = json.data.content[5].company_code;
            input6[13].value = json.data.content[5].area;
            input1[14].value = json.data.content[5].deadline;
            input6[15].value = json.data.content[5].bid_status;

        }
    }
}



//用户完善投标信息 进行提交



function sendVotebid1() {
    var xmlHttp = creatxmlHTTP1();
    function creatxmlHTTP1() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }
    var txt="";//拼接字符串；
    var doc1=document.getElementsByName("bid1");
    var sever_tax=doc1[10].value*0.01+1;
    if(doc1[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        txt = "voteBid_id=" + order_id1 + "&vote_company_code=" + doc1[0].value + "&sale_price=" + doc1[8].value * sever_tax + "&sale_totalprice=" + doc1[9].value * sever_tax;
        var url = local+":8080/voteBid/voteBid";//服务器URL
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.send(txt);
        alert("投标成功");
    }
}

function sendVotebid2() {
    var xmlHttp = creatxmlHTTP2();
    function creatxmlHTTP2() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }
    var txt="";//拼接字符串；
    var doc2=document.getElementsByName("bid2");
    var sever_tax=doc2[10].value*0.01+1;
    if(doc2[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        txt = "voteBid_id=" + order_id2 + "&vote_company_code=" + doc2[0].value + "&sale_price=" + doc2[8].value * sever_tax +
            "&sale_totalprice=" + doc2[9].value * sever_tax;
        var url = local+":8080/voteBid/voteBid";//服务器URL
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.send(txt);
        alert("投标成功");
    }
}


function sendVotebid3() {
    var xmlHttp = creatxmlHTTP3();
    function creatxmlHTTP3() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }
    var txt="";//拼接字符串；
    var doc3=document.getElementsByName("bid3");
    var sever_tax=doc3[10].value*0.01+1;
    if(doc3[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        txt = "voteBid_id=" + order_id3 + "&vote_company_code=" + doc3[0].value + "&sale_price=" + doc3[8].value * sever_tax +
            "&sale_totalprice=" + doc3[9].value * sever_tax;
        var url = local+":8080/voteBid/voteBid";//服务器URL
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.send(txt);
        alert("投标成功");
    }
}

function sendVotebid4() {
    var xmlHttp = creatxmlHTTP4();
    function creatxmlHTTP4() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }
    var txt="";//拼接字符串；
    var doc4=document.getElementsByName("bid4");
    var sever_tax=doc4[10].value*0.01+1;
    if(doc4[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        txt = "voteBid_id=" + order_id4 + "&vote_company_code=" + doc4[0].value + "&sale_price=" + doc4[8].value * sever_tax +
            "&sale_totalprice=" + doc4[9].value * sever_tax;
        var url = local+":8080/voteBid/voteBid";//服务器URL
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.send(txt);
        alert("投标成功");
    }
}

function sendVotebid5() {
    var xmlHttp = creatxmlHTTP5();
    function creatxmlHTTP5() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }

    var txt="";//拼接字符串；
    var doc5=document.getElementsByName("bid5");
    var sever_tax=doc5[10].value*0.01+1;
    if(doc5[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        txt = "voteBid_id=" + order_id5 + "&vote_company_code=" + doc5[0].value + "&sale_price=" + doc5[8].value * sever_tax +
            "&sale_totalprice=" + doc5[9].value * sever_tax;
        var url = local+":8080/voteBid/voteBid";//服务器URL
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.send(txt);
        alert("投标成功");
    }

}

function sendVotebid6() {
    var xmlHttp = creatxmlHTTP6();

    function creatxmlHTTP6() {
        if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlHttp=new XMLHttpRequest();
        }else {
            // IE6, IE5 浏览器执行代码
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlHttp;
    }

    var txt="";//拼接字符串；
    var doc6=document.getElementsByName("bid6");
    var sever_tax=doc6[10].value*0.01+1;
    if(doc6[10]<0.5){
        alert("平台税率必须大于0.5%");
    }else {
        if (doc6[1].value.length == 0) {
        } else {
            txt = "voteBid_id=" + order_id6 + "&vote_company_code=" + doc6[0].value + "&sale_price=" + doc6[8].value * sever_tax +
                "&sale_totalprice=" + doc6[9].value * sever_tax;
            var url =local+ ":8080/voteBid/voteBid";//服务器URL
            xmlHttp.open("POST", url, true);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp.send(txt);
            alert("投标成功");
        }
    }
}




function nextPage_bid_result() {
    page++;
    if(totalPages>page){
        onClickAjax_biding_result1();
    }
    else alert("已经是最后一页");
}


function beforePage_bid_result() {
    page--;
    if(page>=0){
        onClickAjax_biding_result1();
    }
    else alert("第一页");
}